<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>概念众包-运营后台</title>
    <link rel="stylesheet" href="./public/bower_components/bootstrap/dist/css/bootstrap.min.css">
    <script src="./public/dist/js/jquery.min.js"></script>
    <script src="./public/bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="./public/dist/css/index.css">
    <link rel="stylesheet" href="./public/dist/css/spop.min.css">
    <script src="./public/dist/js/spop.min.js"></script>
    <link rel="stylesheet" href="./public/dist/css/loading.css">
    <script src="./public/dist/js/loading.js"></script>
    <link rel="stylesheet" href="./public/dist/css/AdminLTE.min.css">
    <link rel="stylesheet" href="./public/bower_components/font-awesome/css/font-awesome.min.css">
    <style type="text/css">
        table{
            table-layout: fixed;
        }
        td{
            width: 100%;
            word-break: keep-all;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }
        tr{
            cursor: pointer;
        }
        .chen-content {
            min-height: 100%;
            background-color: #ecf0f5;
            z-index: 800;
        }
    </style>
</head>
<body>
<div class="chen-content">
    <section class="content-header">
        <h1>
            众包审核
            <small>Control panel</small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> 审核库</a></li>
            <li class="active">众包审核</li>
        </ol>
    </section>

    <!-- Main content -->
    <section class="content">
        <div class="form-group form-inline" style="float: right;">
            <input type="text" class="form-control" id="code" placeholder="股票代码" autocomplete="off">
            <input type="text" class="form-control" id="name" placeholder="股票名称" autocomplete="off">
            <input type="text" class="form-control" id="concept_name" placeholder="概念名称" autocomplete="off">
            <button type="button" class="btn btn-info" id="search">查询</button>
        </div>
        <div style="text-align: center;">
            <table class="table table-bordered table-hover table-condensed table-striped">
                <colgroup>
                    <col width="10%">
                    <col width="10%">
                    <col width="10%">
                    <col width="30%">
                    <col width="10%">
                    <col width="10%">
                    <col width="10%">
                    <col width="10%">
                </colgroup>
                <thead>
                <tr style="background-color: #3c8dbc;color: white;">
                    <th>股票代码</th>
                    <th>股票名称</th>
                    <th>概念名称</th>
                    <th>概念解析</th>
                    <th>用户昵称</th>
                    <th>众包方式</th>
                    <th>提交时间</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody id="tbody">
                </tbody>
            </table>
            <div class="page_div" id="page" style="margin: 0 auto"></div>
        </div>
    </section>
</div>
</body>
<script type="application/javascript">
    var current = 1;
    var dic = {
        '2': '<span style="color: green">已采纳</span>',
        '3': '<span style="color: red">已驳回</span>'
    };
    var method = {
        '1': '<span style="color: deepskyblue">新增概念股</span>',
        '2': '<span style="color: red">删除概念股</span>'
    };
    $('document').ready(function () {
        doSearch();
        $('#search').click(function () {
            current = 1;
            doSearch();
        });
        $('#tbody').on('click', '#pass', function (event) {
            var id = $(this).parent().parent().data('json');
            apply(id, 2)
        });
        $('#tbody').on('click', '#refuse', function (event) {
            var id = $(this).parent().parent().data('json');
            apply(id, 3)
        });
    });

    function doSearch() {
        var code = $('#code').val();
        var name = $('#name').val();
        var concept_name = $('#concept_name').val();
        loading('正在加载中...');
        $.ajax({
            type:"post",
            url:"./index.php?s=Home/Admin/searchAudit",
            async:true,
            datatype:'json',
            data:{
                page:current,
                code:code,
                code_name: name,
                concept_name: concept_name
            },
            timeout:1000,
            cache:false,
            success:function (data) {
                appendHtml(data.data);
                updatePage(data.page,data.num,data.total);
                removeLoading('loading');
            }
        });
    }
    function appendHtml(data) {
        var html = '';
        for (var i in data) {
            html += '<tr data-json="'+ data[i].id +'">';
            html += '<td>' + data[i].code + '</td>';
            html += '<td>' + data[i].code_name + '</td>';
            html += '<td>' + data[i].concept_name + '</td>';
            html += '<td>' + data[i].explain + '</td>';
            html += '<td>' + data[i].author + '</td>';
            html += '<td>' + method[data[i].method] + '</td>';
            html += '<td>' + data[i].ctime + '</td>';
            if (data[i].status == 1) {
                html += '<td><button class="btn btn-info" id="pass">通过</button><button class="btn btn-danger" id="refuse">驳回</button></td>';
            } else {
                html += '<td>'+dic[data[i].status]+'</td>';
            }
            html += '</tr>';
        }
        $('#tbody').html(html);
    }
    function updatePage(page, totalpage, total, sort) {
        $("#page").paging({
            pageNo:page,
            totalPage:totalpage,
            totalSize:total,
            callback:function(num) {
                current = num;
                doSearch(num);
            }
        })
    }
    function apply(id, status) {
        loading('正在加载中...');
        $.ajax({
            type:"post",
            url:"./index.php?s=Home/Admin/apply",
            async:true,
            datatype:'json',
            data:{
                id: id,
                status: status
            },
            timeout:1000,
            cache:false,
            success:function (data) {
                removeLoading('loading');
                if (data.code == 0) {
                    show('更新成功', 'success');
                    doSearch();
                } else {
                    show('更新失败', 'error');
                }
            },
            error: function (error) {
                removeLoading('loading');
                show('系统错误', 'error');
            }
        });
    }
</script>
</html>